package org.shj.util;

import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.utility.Predefine;

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * @author Shen Huang Jian
 * @date 2020-08-27 9:21
 */
public class PropertyUtil {

    private static Properties properties;

    static{
        properties = new Properties();
        try {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            if (loader == null)
            {  // IKVM (v.0.44.0.5) doesn't set context classloader
                loader = HanLP.Config.class.getClassLoader();
            }

            properties.load(new InputStreamReader(Predefine.HANLP_PROPERTIES_PATH == null ?
                    loader.getResourceAsStream("hanlp.properties") :
                    new FileInputStream(Predefine.HANLP_PROPERTIES_PATH)
                    , "UTF-8"));
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("找不到配置文件： hanlp.properties");
            System.exit(-1);
        }
    }

    public static String getRootDataFolder(){
        return properties.getProperty("root");
    }

    public static String getString(String key){
        return properties.getProperty(key);
    }
}
